//
//  HCustomNumberView.m
//  逆向工程
//
//  Created by 朱同海 on 17/5/22.
//  Copyright © 2017年 朱同海. All rights reserved.
//

#import "HCustomNumberView.h"

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
@interface HCustomNumberView ()<UITextViewDelegate>
@property (nonatomic, strong) UILabel    *titleLabel;
@property (nonatomic, strong) UIButton   *saveBtn;
@property (nonatomic, strong) UIButton   *clearBtn;
@property (nonatomic, strong) UIButton   *quicklyReturnBtn;
@property (nonatomic, strong) UIButton   *clearAllBtn;


@end

@implementation HCustomNumberView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}

- (void)createUI {
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.titleLabel];
    [self addSubview:self.myTextView];
    [self addSubview:self.saveBtn];
    [self addSubview:self.clearBtn];
    [self addSubview:self.quicklyReturnBtn];
    [self addSubview:self.clearAllBtn];

}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat viewWidth = self.frame.size.width;
    self.titleLabel.frame = CGRectMake(0, 0, viewWidth, 20);
    self.myTextView.frame = CGRectMake(-1, 20, viewWidth + 2, 200);
    
    self.saveBtn.frame = CGRectMake(15, 230, 80, 30);
    self.clearBtn.frame = CGRectMake(viewWidth - 90, 230, 80, 30);

    self.quicklyReturnBtn.frame = CGRectMake(15, 280, 80, 30);
    self.clearAllBtn.frame = CGRectMake(viewWidth - 90, 280, 80, 30);
}

- (void)setTitleLabelText:(NSString *)string {
    self.titleLabel.text = [NSString stringWithFormat:@"编号:%@", string];
}

- (void)actionBtnClick:(UIButton *)button{
    if (self.BtnBlock) {
        self.BtnBlock(button);
    }
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textColor = [UIColor blackColor];
    }
    return _titleLabel;
}

- (UITextView *)myTextView {
    if (!_myTextView) {
        _myTextView = [[UITextView alloc] init];
        _myTextView.delegate = self;
        _myTextView.layer.borderColor = [UIColor blackColor].CGColor;
        _myTextView.layer.borderWidth = 1.0f;
    }
    return _myTextView;
}

- (UIButton *)saveBtn {
    if (!_saveBtn) {
        _saveBtn = [[UIButton alloc] init];
        _saveBtn.tag = 1314;
        [_saveBtn setTitleColor:[[UIColor blackColor] colorWithAlphaComponent:0.7] forState:UIControlStateNormal];
        [_saveBtn setTitle:@"保存内容" forState:UIControlStateNormal];
        _saveBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_saveBtn addTarget:self action:@selector(actionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _saveBtn.layer.borderColor = [UIColor blackColor].CGColor;
        _saveBtn.layer.borderWidth = 0.5f;
        _saveBtn.layer.cornerRadius = 10;
        _saveBtn.layer.masksToBounds = YES;
    }
    return _saveBtn;
}

- (UIButton *)clearBtn {
    if (!_clearBtn) {
        _clearBtn = [[UIButton alloc] init];
        _clearBtn.tag = 1315;
        [_clearBtn setTitleColor:[[UIColor blackColor] colorWithAlphaComponent:0.7] forState:UIControlStateNormal];
        [_clearBtn setTitle:@"清除内容" forState:UIControlStateNormal];
        _clearBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_clearBtn addTarget:self action:@selector(actionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _clearBtn.layer.borderColor = [UIColor blackColor].CGColor;
        _clearBtn.layer.borderWidth = 0.5f;
        _clearBtn.layer.cornerRadius = 10;
        _clearBtn.layer.masksToBounds = YES;
    }
    return _clearBtn;
}

- (UIButton *)quicklyReturnBtn {
    if (!_quicklyReturnBtn) {
        _quicklyReturnBtn = [[UIButton alloc] init];
        _quicklyReturnBtn.tag = 1316;
        [_quicklyReturnBtn setTitleColor:[[UIColor blackColor] colorWithAlphaComponent:0.7] forState:UIControlStateNormal];
        [_quicklyReturnBtn setTitle:@"快速跳转" forState:UIControlStateNormal];
        _quicklyReturnBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_quicklyReturnBtn addTarget:self action:@selector(actionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _quicklyReturnBtn.layer.borderColor = [UIColor blackColor].CGColor;
        _quicklyReturnBtn.layer.borderWidth = 0.5f;
        _quicklyReturnBtn.layer.cornerRadius = 10;
        _quicklyReturnBtn.layer.masksToBounds = YES;
    }
    return _quicklyReturnBtn;
}

- (UIButton *)clearAllBtn {
    if (!_clearAllBtn) {
        _clearAllBtn = [[UIButton alloc] init];
        _clearAllBtn.tag = 1317;
        [_clearAllBtn setTitleColor:[[UIColor blackColor] colorWithAlphaComponent:0.7] forState:UIControlStateNormal];
        [_clearAllBtn setTitle:@"清空缓存" forState:UIControlStateNormal];
        _clearAllBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_clearAllBtn addTarget:self action:@selector(actionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _clearAllBtn.layer.borderColor = [UIColor blackColor].CGColor;
        _clearAllBtn.layer.borderWidth = 0.5f;
        _clearAllBtn.layer.cornerRadius = 10;
        _clearAllBtn.layer.masksToBounds = YES;
    }
    return _clearAllBtn;
}
@end












